#ifndef BOOTSTRAP_H
#define BOOTSTRAP_H

#include <QtService>
#include <head/g_functionbase.h>
#include <element/baseudpreceiver.h>
#include <support/mysql_helper.h>
#include "g_ver.h"
#include "m_fhs.h"

class Bootstrap : public QObject
{
    Q_OBJECT
public:
    explicit Bootstrap(QObject *parent = nullptr);

    void start();
    void stop();
    bool connectDB();
    void dbTry();
    void updateDataSource();
    QCborMap fetchData(const QString &entry);

    void startReceiver();
    void stopReceiver();

    void appendLog(const QString &event,
                   QtServiceBase::MessageType type=QtServiceBase::Information);

    void onReceived(const QByteArray data);
    void sendReply(const QString &clientIP,
                   const QCborMap &reply);

signals:

protected:
    void timerEvent(QTimerEvent *);

private:
    QString dsTable;

    BaseUdpReceiver *receiver;
    QThread recvThread;

    QSqlDatabase db;
    QMap<QString,QCborMap> dataSource;
};

#endif // BOOTSTRAP_H
